from django.db import models


class Goods(models.Model):
    name = models.CharField(max_length=100)
    price = models.DecimalField(max_digits=7, decimal_places=2)
    stock = models.IntegerField()
    sales = models.IntegerField()

    class Meta:
        db_table = 'sp_goods'


class TinyintField(models.Field):
    def db_type(self, connection):
        return 'tinyint'

class Order(models.Model):
    uid = models.IntegerField()
    order_code = models.CharField(max_length=100)
    total_count = models.IntegerField()
    total_amount = models.DecimalField(max_digits=7, decimal_places=2)
    status = TinyintField(default=1)

    class Meta:
        db_table = 'sp_order'


class OrderDetail(models.Model):
    uid = models.IntegerField()
    order_code = models.CharField(max_length=100)
    goods_id = models.IntegerField()
    counts = models.IntegerField()
    price = models.DecimalField(max_digits=7, decimal_places=2)

    class Meta:
        db_table = 'sp_orderdetail'